package com.lancoo.ccas53.arrangecourse.AlgDataSource.dataprocess.Impl;

import com.lancoo.ccas53.arrangecourse.AlgDataSource.common.Constants;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/**
 * @Description 公共数据处理
 * @Author Fortysun
 * @Date 2023/4/13 14:15
 **/
public class PublicDataService {

    protected List<Integer> initConnectSection() {
        //控制各个连上节次的占比，1，2，3，4
        double[] floats = {0.008, 0.988, 0.006, 0.006};

        //计算不同授课类型的教学班总数
        int teachingClassCount = Constants.COLLEGE_NUM*//院系数
                Constants.COLLEGE_COURSE_NUM *//每个院系的课程数
                Constants.COURSE_TEACHING_CLASS_NUM*//每个课程的教学班数量
                Constants.COURSE_TYPE_NUM;//每个课程的授课种类
        List<Integer> connectSectionList = new ArrayList<>();
        for (int i = 0; i < teachingClassCount; i++) {
            if (i < teachingClassCount * floats[0]) {//前10%
                connectSectionList.add(1);
            } else if (i < teachingClassCount * floats[1]) {//10%~90%
                connectSectionList.add(2);
            } else if (i < teachingClassCount * floats[2]) {//90%~95%
                connectSectionList.add(3);
            }
            else{//95%~100%
                connectSectionList.add(4);
            }
        }
//        //列表乱序，将分布打散
        Collections.shuffle(connectSectionList);

        return connectSectionList;
    }

    /**
     * 初始化授课类型，所需教室的的比例，0.5：讲授，0.2：实验，0.2：上机，0.1：其他
     * @param roomNum 教室数量
     * @return
     */
    protected List<Integer> initHourType(int roomNum) {
        //控制各种授课类型的占比
        double[] floats = {0.5, 0.2, 0.2, 0.1};

        List<Integer> roomProportionList = new ArrayList<>();

        for (int j = 0; j < roomNum; j++) {
            if (j < roomNum * (floats[0])) {//前50%
                roomProportionList.add(1);
            } else if (j < roomNum * (floats[0] + floats[1])) {//50%~70%
                roomProportionList.add(2);
            } else if (j < roomNum * (floats[0] + floats[1] + floats[2])) {//70%~90%
                roomProportionList.add(3);
            }
            else{//90%~100%
                roomProportionList.add(4);
            }
        }

        return roomProportionList;
    }

    /**
     * 初始化教学班的授课类型
     * @param teachingClassNum 教学班数量
     * @return
     */
    protected HashMap<Integer, List<Integer>> initTeachingClassHourType(int teachingClassNum) {
        List<Integer> roomProportionList = initHourType(teachingClassNum);

        List<Integer> hourType1List = new ArrayList<>();
        List<Integer> otherHourTypeList = new ArrayList<>();

        /***将列表拆分成两个列表，分成讲授和其他**/
        for (Integer hourType : roomProportionList) {
            if (hourType.equals(1)) {
                hourType1List.add(hourType);
            } else {
                otherHourTypeList.add(hourType);
            }
        }
        //用来保存对应教学班的两种授课类型
        HashMap<Integer, List<Integer>> hourTypeMap = new HashMap<>();
        int index = 0;
        for (Integer hourType : hourType1List) {
            //用来保存每个教学班的两种授课类型
            List<Integer> teachingClassHourType = new ArrayList<>();
            //保存教学班的讲授类型
            teachingClassHourType.add(hourType);
            //保存教学班的除讲授以外的授课类型
            teachingClassHourType.add(otherHourTypeList.get(index));
            //将教学班的授课类型信息，添加到map中
            hourTypeMap.put(index, teachingClassHourType);
            index++;
        }

        return hourTypeMap;
    }

    /**
     * 根据不同的授课类型，指定不同类型的教室类型
     * @param hourType 授课类型 1：讲授，：实验、3：上机、4：其他
     * @return
     */
    protected Integer getRoomType(int hourType) {
        int roomType = -1;
        switch (hourType) {
            case 1:
                roomType = 21;//AI智慧教室
                break;
            case 2:
                roomType=46;//实验室
                break;
            case 3:
                roomType=31;//普通电脑室，机房；
                break;
            case 4:
                roomType =45;//操场；
                break;
            default:
                System.out.println("PublicDataService--getRoomType: hourType is not suitable, hourType=" + hourType);
                break;
        }
        return roomType;
    }


}
